<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      var arr1 = [1, 12, 3, 4, 5]
      var arr2 = [111, 3, 24,5,2,6,10]
      var newArr = []
      for (var i = 0; i < arr1.length; i++) {
        for (var j = 0; j < arr2.length; j++) {
            if (arr1[i] == arr2[j]) {
                 newArr[newArr.length] = arr2[j]
            }
        }
      }
      console.log(newArr);
    </script>
  </body>
</html>
